﻿/**
* QSmart Andon
*
* 2012-10-11
* 
* steven.li
*
* Copyright(c) 2012 All Rights Reserved. Taiyou Tech(GUANGZHOU) Co.,Ltd.  (广州太友科技) [ sales@gztaiyou.com]. 
*
*/
using System;
using System.Collections;
using FX.CC.Andon.Entity.SystemManage;
using FX.CC.Andon.Service.SystemManage;
using FX.CC.Andon.Utility.Json;

namespace FX.CC.Andon.Business.SystemManage
{
    public class DeptBusiness
    {
        private readonly DeptService _dal = new DeptService();

        /// <summary>
        /// 获取部门绑定下拉列表
        /// </summary>
        /// <returns></returns>
        public string GetDeptList()
        {
            return JsonHelper.Encode(_dal.GetDeptList());
        }

        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool AddDept(string data)
        {
            var model = new DepartmentEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.DptID = Guid.NewGuid();
                model.DptName = row["DptName"].ToString();
                model.DptDesc = row["DptDesc"] != null ? row["DptDesc"].ToString() : "";
            }
            return _dal.AddDept(model);
        }

        /// <summary>
        /// 修改部门
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool ModifyDept(string data)
        {
            var model = new DepartmentEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.DptID = new Guid(row["DptID"].ToString());
                model.DptName = row["DptName"].ToString();
                model.DptDesc = row["DptDesc"] != null ? row["DptDesc"].ToString() : "";
            }
            return _dal.ModifyDept(model);
        }

        /// <summary>
        /// 获取部门单条信息
        /// </summary>
        /// <param name="dptId"></param>
        /// <returns></returns>
        public string GetDeptInfo(string dptId)
        {
            return JsonHelper.Encode(_dal.GetDeptInfo(dptId));
        }

        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="dptId"></param>
        /// <returns></returns>
        public bool Remove(string dptId)
        {
            return _dal.Remove(dptId);
        }

        /// <summary>
        /// 获取部门分页
        /// </summary>
        /// <returns></returns>
        public string GetDeptList(DepartmentQcEntity qcmodel)
        {
            var total = _dal.GetDeptCount(qcmodel);
            var list = _dal.GetDeptList(qcmodel);
            return JsonHelper.Encode(total, list);
        }
    }
}
